package com.buka.communicate.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.adapter.CommentAdapter;
import com.buka.communicate.adapter.PraiseHeadAdapter;
import com.buka.communicate.views.MyRecylerView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.pizidea.imagepicker.AndroidImagePicker;
import com.pizidea.imagepicker.bean.ImageItem;
import com.pizidea.imagepicker.image.ImagePreviewActivity;

import net.neiquan.applibrary.base.BaseActivity;
import net.neiquan.applibrary.wight.MyNineGridLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/17 0017.
 */

public class FriendDetailActivity extends BaseActivity {
    @InjectView(R.id.mHeadImg)
    SimpleDraweeView mHeadImg;
    @InjectView(R.id.mUserName)
    TextView mUserName;
    @InjectView(R.id.mUserAge)
    TextView mUserAge;
    @InjectView(R.id.mUserLevel)
    TextView mUserLevel;
    @InjectView(R.id.mFamilyTv)
    TextView mFamilyTv;
    @InjectView(R.id.mContentTv)
    TextView mContentTv;
    @InjectView(R.id.layout_nine_grid)
    MyNineGridLayout layoutNineGrid;
    @InjectView(R.id.mTimeTv)
    TextView mTimeTv;
    @InjectView(R.id.mPraiseTv)
    TextView mPraiseTv;
    @InjectView(R.id.mPraiseLL)
    LinearLayout mPraiseLL;
    @InjectView(R.id.mCommentTv)
    TextView mCommentTv;
    @InjectView(R.id.mCommentLL)
    LinearLayout mCommentLL;
    @InjectView(R.id.mPraiseRecylerView)
    RecyclerView mPraiseRecylerView;
    @InjectView(R.id.mCommentRecylerView)
    MyRecylerView mCommentRecylerView;
    @InjectView(R.id.mCommentET)
    EditText mCommentET;
    @InjectView(R.id.mEmotionLogo)
    ImageView mEmotionLogo;

    @Override
    public int getRootViewId() {
        return R.layout.activity_friend_detail;
    }

    @Override
    public void setViews() {
        setTitleTv("动态详情");
        mHeadImg.setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
        Spanned spanned = Html.fromHtml("来自家族 <font color='#58e4df'><u>美人鱼的眼泪</u></font>");
        mFamilyTv.setText(spanned);
        initNineGridLayout();
        initPraiseRecylerView();
        initCommentRecylerView();
    }

    private void initNineGridLayout() {
        List<String> mUrls = new ArrayList<>();
        mUrls.add("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510910397110&di=3aa93fddfc7d8fdf37df366f1317dabb&imgtype=0&src=http%3A%2F%2Feasyread.ph.126.net%2FYybMgLmKMgxIPz6AlWhEnw%3D%3D%2F7917092849429000484.jpg");
        layoutNineGrid.setUrlList(mUrls);
        layoutNineGrid.setOnImgClickListener(new MyNineGridLayout.OnImgClickListener() {
            @Override
            public void onClick(int p, String url, List<String> urlList) {
                final ArrayList<ImageItem> mImageList = new ArrayList<>();
                mImageList.clear();
                if (urlList != null && urlList.size() > 0) {
                    for (int i = 0; i < urlList.size(); i++) {
                        ImageItem imageItem = new ImageItem();
                        imageItem.setPath(urlList.get(i));
                        mImageList.add(imageItem);
                    }
                    Intent intent = new Intent();
                    intent.putExtra(AndroidImagePicker.KEY_PIC_SELECTED_POSITION, p);
                    intent.setClass(FriendDetailActivity.this, ImagePreviewActivity.class);
                    intent.putParcelableArrayListExtra(ImagePreviewActivity.IMAGEURL, mImageList);
                    startActivity(intent);
                }
            }
        });
    }

    private void initPraiseRecylerView() {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(8,
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        mPraiseRecylerView.setLayoutManager(layoutManager);
        mPraiseRecylerView.setAdapter(new PraiseHeadAdapter(this, null));
    }

    private void initCommentRecylerView() {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        mCommentRecylerView.setLayoutManager(layoutManager);
        mCommentRecylerView.setAdapter(new CommentAdapter(this,null));
        mCommentRecylerView.setNestedScrollingEnabled(false);
    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.mFamilyTv, R.id.mEmotionLogo})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mFamilyTv:
                break;
            case R.id.mEmotionLogo:
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }
}
